package com.chezhujie.www.service;

import com.chezhujie.www.domain.Czjgiving;
import com.chezhujie.www.persistence.CzjgivingMapper;
import com.xy.core.exception.ClassCheckException;
import com.xy.user.base.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;


/**
 * 赠送二维码
 * Created by 汤伟杰 on 2017/5/23.
 */
@Service
public class CzjgivingService extends BaseService<Czjgiving> {
    @Autowired
    private CzjgivingMapper czjgivingMapper;

    @Autowired
    public void setBaseMapper(CzjgivingMapper czjgivingMapper) {
        this.baseMapper = czjgivingMapper;
    }

    public List<Map<String,Object>> getListActId(Map<String, Object> param) {
        return czjgivingMapper.listActId(param);
    }
    public List<Map<String,Object>> getListAwardstockId(Map<String, Object> param) {
        return czjgivingMapper.listAwardstockId(param);
    }

    public void checkEntity(Czjgiving czjgiving) throws ClassCheckException {
        if(czjgiving.getGivingId()!=null&&czjgiving.getGivingId().length()>19){
            throw new ClassCheckException("赠送二维码主键不能超过19个字符");
        }
        if(czjgiving.getActId()!=null&&czjgiving.getActId().length()>19){
            throw new ClassCheckException("赠送二维码活动id不能超过19个字符");
        }
        if(czjgiving.getAwardstockId()!=null&&czjgiving.getAwardstockId().length()>19){
            throw new ClassCheckException("赠送二维码库存奖品id不能超过19个字符");
        }
    }
    public void checkListEntity(List<Czjgiving> listCzjgiving) throws ClassCheckException {

        for (Czjgiving czjgiving : listCzjgiving) {
            checkEntity(czjgiving);
        }

    }
}
